package com.ruoyi.web.dorm.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.dorm.entity.StudentHealthEntity;
import com.ruoyi.web.dorm.entity.VisitorEntity;
import com.ruoyi.web.dorm.service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/dorm/visitor")
public class VisitorController extends BaseController {
    @Autowired
    private VisitorService visitorService;

    /**
     * 条件查询访客信息
     * @param visitorEntity
     * @return
     */
    @GetMapping("/getVisitor")
    public TableDataInfo getVisitor(VisitorEntity visitorEntity){
        startPage();
        return getDataTable(visitorService.getVisitor(visitorEntity));
    }


    /**
     * 添加访客记录
     * @param visitorEntity
     * @return
     */
    @PostMapping("/addVisitor")
    public AjaxResult addVisitor(@RequestBody VisitorEntity visitorEntity){
        return toAjax(visitorService.addVisitor(visitorEntity));
    }

    /**
     * 查询访客信息导出信息
     * @param visitorEntity
     * @return
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response,  VisitorEntity visitorEntity){
        List<VisitorEntity> list = visitorService.getVisitor(visitorEntity);
        ExcelUtil<VisitorEntity> util = new ExcelUtil<>(VisitorEntity.class);
        util.exportExcel(response,list,"访客记录数据");
    }


}
